package timing.ukulele.flow.extention;

import org.activiti.bpmn.model.ExtensionAttribute;
import org.activiti.bpmn.model.ExtensionElement;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.bpmn.parser.handler.UserTaskParseHandler;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyUserTaskParseHandler extends UserTaskParseHandler implements UserTaskExtensionElementProperty {

    @Override
    protected void executeParse(BpmnParse bpmnParse, UserTask userTask) {
        //调用上层的解析
        super.executeParse(bpmnParse, userTask);
        FlowElement flowElement = bpmnParse.getBpmnModel().getFlowElement(userTask.getId());
        ExtensionElement extensionElement = parseUserTaskExtensionElement(userTask);
        flowElement.addExtensionElement(extensionElement);
    }

    public ExtensionElement parseUserTaskExtensionElement(UserTask userTask) {
        Map<String, ExtensionElement> operationMap = new HashMap<>();
        //获取扩展属性标签元素
        Map<String, List<ExtensionElement>> extensionElements = userTask.getExtensionElements();
        if(CollectionUtils.isEmpty(extensionElements))
            return null;
        List<ExtensionElement> customProperties = extensionElements.get(elememt);
        if(CollectionUtils.isEmpty(customProperties))
            return null;
        for(ExtensionElement element: customProperties){
            Map<String, List<ExtensionAttribute>> attributes = element.getAttributes();
        }
        return null;
    }
}
